home *** CD-ROM | disk | FTP | other *** search
- {
- Example of using the 3D "engine", by Maple Leaf, 1996
-
- This code is freeware. If you find it useful, feel free to do whatever
- you want with it, with only one condiion: give some small greetings to
- Maple Leaf in your productions that use parts of it.
-
- Maple Leaf, '96
-
- btw, I'm too lazy to write down kilos of comments... :-)
- }
- uses xmode,crt,engine3d;
-
- var a,b:word;
- pal:array[byte] of record r,g,b:byte end;
- capag,cvpag : word;
- dd:integer;
- coord:array[0..730] of record x,y,z:integer end;
- RealMapping : Boolean;
- ch:char;
- MaxPnt:word;
- RotStep,TiltStep:longint;
-
- Procedure GenFig;
- var cnt,k:word; angle,angle2,rad:real;
- begin
- cnt:=0;
- angle:=0;
- k:=0;
- repeat
- angle2:=0;
- rad:=abs(40*sin(angle));
- repeat
- with coord[cnt] do begin
- x:=Trunc(rad*cos(angle2*pi/180));
- y:=Trunc(rad*sin(angle2*pi/180));
- z:=k*6;
- end;
- inc(cnt);
- angle2:=angle2+10; {?}
- until (cnt>720) or (angle2>=360);
- angle:=angle+2*pi/19; {?}
- inc(k);
- until cnt>720;
- MaxPnt:=cnt
- end;
-
- Procedure PuneFig;
- var i:integer; cnt:word;
- begin
- cnt:=0;
- {xvwait;}
- xclrvpage(capag);
- for i:=0 to MaxPnt-1 do begin
- _3dx:=coord[i].x+100;
- _3dy:=coord[i].y;
- _3dz:=coord[i].z+10;
- asm
- cmp RealMapping,1
- je @1
- call IntMapCoordinates
- jmp @2
- @1:call MapCoordinates
- @2:
- end;
- xvplot(_2dx,_2dy,i shr 2,capag);
- end;
- end;
-
- Procedure IntroText;
- begin
- Writeln('3D Figure, by Maple Leaf, 1996.');
- Writeln(#13#10,' Hot keys are:'#13#10);
- Writeln(' <M> - Change mapping method (float/integer)');
- Writeln(' <Left> - Decrement horizontal speed of rotation');
- Writeln(' <Right> - Increment horizontal speed of rotation');
- Writeln(' <Up> - Increment vertical speed of rotation');
- Writeln(' <Down> - Decrement vertical speed of rotation');
- Writeln(#13#10'Press a key to start ...');
- Readkey;
- end;
-
- begin
- ClrScr;
- GenFig;
- IntroText;
- xinitvideo(0);
- xclrvram;
- for a:=1 to 255 do with pal[a] do begin
- r:=Trunc(63*a/255);
- g:=Trunc(40);
- b:=Trunc(63-63*a/255);
- end;
- xsetpalette(@pal);
- ZoomFactor:=500;
- Perspective:=True;
- SetObserverPosition(0,0,500);
- SetAngles(0,0);
- capag:=0;
- cvpag:=3;
- dd:=10;
- RealMapping:=false;
- RotStep:=2;
- TiltStep:=3;
- repeat
- repeat
-
- xvwait;
- xsetvpage(cvpag);
-
- RotAngle:=RotAngle+RotStep;
- TiltAngle:=TiltAngle+TiltStep;
- if RotAngle>359 then RotAngle:=360-RotAngle;
- if RotAngle<0 then RotAngle:=360+RotAngle;
- if TiltAngle>359 then TiltAngle:=360-TiltAngle;
- if TiltAngle<0 then TiltAngle:=360+TiltAngle;
- {SetAngles(RotAngle,TiltAngle);}
-
- PuneFig;
-
- inc(capag); if capag>3 then capag:=0;
- inc(cvpag); if cvpag>3 then cvpag:=0;
-
- until keypressed;
- ch:=readkey;
- case UpCase(ch) of
- 'M': { Mapping mode } RealMapping:=not RealMapping;
- #0: begin
- ch:=readkey;
- case ch of
- #72: {Up} inc(RotStep);
- #80: {Down} dec(RotStep);
- #75: {Left} dec(TiltStep);
- #77: {Right} inc(TiltStep);
- end;
- end;
- end;
- until ch=#27;
- textmode(25);
- end.